package com.qumitech.visualnovel.component.util.bash;


import com.qumitech.visualnovel.component.config.Config;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import lombok.extern.slf4j.Slf4j;

/**
 * //                       _oo0oo_
 * //                      o8888888o
 * //                      88" . "88
 * //                      (| -_- |)
 * //                      0\  =  /0
 * //                    ___/`---'\___
 * //                  .' \\|     |// '.
 * //                 / \\|||  :  |||// \
 * //                / _||||| -:- |||||- \
 * //               |   | \\\  -  /// |   |
 * //               | \_|  ''\---/''  |_/ |
 * //               \  .-\__  '-'  ___/-. /
 * //             ___'. .'  /--.--\  `. .'___
 * //          ."" '<  `.___\_<|>_/___.' >' "".
 * //         | | :  `- \`.;`\ _ /`;.`/ - ` : | |
 * //         \  \ `_.   \_ __\ /__ _/   .-` /  /
 * //     =====`-.____`.___ \_____/___.-`___.-'=====
 * //                       `=---='
 * //
 * //
 * //     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 * //
 * //               佛祖保佑         永无BUG
 * <p>
 * com.qumitech.visualnovel.component.util.bash
 * Created on 2020/9/8.
 */
@Slf4j
public class PythonUtils {

    private static final String RUNNER = Config.getProperty("app.python.runner");

    public static void execute(String pythonFile, String... args) {
        List<String> commands = new ArrayList<>(Arrays.asList("bash", RUNNER, pythonFile));
        if (args != null) {
            commands.addAll(Arrays.asList(args));
        }
        String[] array = new String[commands.size()];
        commands.toArray(array);
        log.info("command: {}", commands);
        try {
            Process process = new ProcessBuilder().command(array).redirectErrorStream(true
            ).redirectErrorStream(true).start();
        } catch (IOException e) {
            log.error("failed to execute python,", e);
        }
    }

    public static void main(String[] args) {
//        System.out.println(execute("jobs/test.py"));
    }
}
